<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/messages.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<%@ include file="/commons/validation.jsp"%>
<%@ include file="/commons/dateTime.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>
<title>违规登记</title>
<script>
var flagtip  = null;
function next(url){
	window.location.href = url;
}

/**
 * 功能描述： 如果房号验证成功，根据房号返回该房屋需要显示在界面上的信息
 */
 function setOwnerAndMeterDate(){
 	var houseId = $('houseId').value;
 	loadRequistion(houseId);
  }

/**
 * 功能描述： 如果房号验证失败，清除上次选房时间信息
 */
 function clearCustomerName(response){
 	var msg = response.responseText;
	validationAlert("houseNumber",false,msg);
    $('burdenMan').innerText='';
	$('renovateLicenceNO').innerText='';
	$('renovateLicenceId').value='';
	$('burdenManPhone').value='';
	$('owner').innerText='';
	$('linkMan').innerText = '';
	$('linkManPhone').innerText = '';
	$('companyName').innerText = '';
 }

var clickButton="";
function addViolation(clickType){
    clickButton = clickType;
	var isTrue=$('violationForm').fireEvent("onSubmit") ;
    if(isTrue){
       var param = Form.serialize('violationForm');
       if(flagtip=="add")
       	 var url = "${ctx}/renovation_renovateViolationAction.do?method=addRenovateViolation";
       else
         var url = "${ctx}/renovation_renovateViolationAction.do?method=editRenovateViolation";
       new Ajax.Request(url,{method: 'post',parameters :param ,onSuccess : showResult});
	}
}
function showResult(response){
	ajaxSubmitException(response.responseText);
	findFrame("main").reloadRenovate();
	if(clickButton=="save_add"){
		$('deptId').options[0].selected = true;
		$('categoryId').options[0].selected = true;
		$('completeDate').value="";
		$('description').value="";
	}else{
		windowClose();
	}
}

function loadRequistion(houseId){
	var url = "${ctx}/renovation_renovateViolationAction.do?method=loadRenovateRequisiteInfo";
	var parameters = "houseId="+houseId;
	new Ajax.Request(url,{method: 'post', parameters: parameters, onComplete: showResponse} );
}
function showResponse(response){
//	clearCustomerName();
//	ajaxSubmitException(response.responseText);
	var obj=eval('(' + response.responseText + ')');
	$('burdenMan').innerText=obj.burdenMan;
	$('renovateLicenceNO').innerText=obj.renovateLicenceNO;
	$('renovateLicenceId').value=obj.renovateLicenceId;
	$('burdenManPhone').value=obj.burdenManPhone;
	$('owner').innerText=obj.owner;
	$('linkMan').innerText = obj.linkMan;
	$('linkManPhone').innerText = obj.linkManPhone;
	$('companyName').innerText = obj.companyName;
}
function choiceHouse(){
	var url = "${ctx}/customer_chooseSingleHouseAction.do?method=chooseBuildingMain";
	top.windowOpen(url, "choiceHouse", "", 500, 800);
}
function setHouseInfo(houseId,houseNum){
		$('houseId').value = houseId;
		$('houseNumber').value = houseNum;
	//	loadRequistion(houseId);
		$('houseNumber').fireEvent("onblur");
}
function init(flag){
	flagtip = flag;
	if(flagtip == 'update'){
		$('editHouseNumber').style.display = 'block';
		$('addHouseNumber').style.display = 'none';
		$('saveAdd').style.display = 'none';
	}
}
</script>
</head>

<body onload="init('${flag }');">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="window_head_outBg">
		<table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td><img src="${ctx}/images/ico_Advance.gif" width="16"
					height="16" align="absmiddle" /> <span class="window_head_intext">违规登记</span></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="aux_header_line_1"></td>
	</tr>
	<tr>
		<td class="aux_header_line_2"></td>
	</tr>
	<tr>
		<td class="content">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td valign="top" class="aux_outtable_color">
				<form name="violationForm"
					action="${ctx}/renovation_renovateViolationAction.do?method=addRenovateViolation"
					method="post" class="required-validate"><input type="hidden"
					name="houseId" value="${violation.houseId }"> <input
					type="hidden" name="keyword" value="${violation.keyword }">
				<input type="hidden" id="nowDate" name="nowDate" value="${nowDate }" />
				<input type="hidden" name="renovateLicenceId"
					value="${violation.renovateLicenceId }">
				<table width="100%" border="0" cellpadding="0" cellspacing="1"
					class="aux_intable_color">
					<tr>
						<td class="aux_intable_td1">房 号：</td>
						<td class="aux_intable_require">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr id="addHouseNumber">
								<td><input name="houseNumber" readonly="readonly"
									class="required validate-ajax" relativeId="houseId"
									onSuccess="setOwnerAndMeterDate" onFailure="clearCustomerName"
									validateUrl="${ctx}/renovation_renovateViolationAction.do?method=validateHouse"
									type="text" size="16" value="${violation.houseNumber }"
									afterInsert="bdAfter" /></td>
								<td width="4">&nbsp;</td>
								<td><a href="#" onClick="choiceHouse();"
									onFocus="this.blur()"><img
									src="${ctx}/images/ico_houesno.GIF" alt="请点选查找房号" border="0"></a><span
									id="bdAfter"></span></td>
							</tr>
							<tr id="editHouseNumber" style="display: none;">
								<td>${violation.houseNumber }&nbsp;</td>
								<td width="4">&nbsp;</td>
								<td>&nbsp;</td>
							</tr>
						</table>
						</td>
						<td class="aux_intable_td1">业主姓名：</td>
						<td class="aux_intable_td2" id="owner">${violation.owner
						}&nbsp;</td>
					</tr>
					<tr>
						<td class="aux_intable_td1">装修许可证号：</td>
						<td class="aux_intable_td2" id="renovateLicenceNO">${violation.renovateLicenceNO
						}&nbsp;</td>
						<td class="aux_intable_td1">装修承建商：</td>
						<td class="aux_intable_td2" id="companyName">${violation.companyName
						}&nbsp;</td>
					</tr>
					<tr>
						<td class="aux_intable_td1">装修联系人：</td>
						<td class="aux_intable_td2" id="linkMan">${violation.linkMan
						}&nbsp;</td>
						<td class="aux_intable_td1">联系电话：</td>
						<td class="aux_intable_td2"><input name="linkManPhone"
							type="text" class="" value="${violation.linkManPhone }" size="16"
							maxlength="30" /></td>
					</tr>
					<tr>
						<td class="aux_intable_td1">现场负责人：</td>
						<td class="aux_intable_td2" id="burdenMan">${violation.burdenMan
						}&nbsp;</td>
						<td class="aux_intable_td1">联系电话：</td>
						<td class="aux_intable_td2"><input name="burdenManPhone"
							type="text" class="" value="${violation.burdenManPhone }"
							size="16" maxlength="30" /></td>
					</tr>
					<tr>
						<td class="aux_intable_td1">检查人：</td>
						<td class="aux_intable_require"><input name="checkMan"
							type="text" class="required" value="${violation.checkMan }"
							size="16" maxlength="36" /></td>
						<td class="aux_intable_td1">检查日期：</td>
						<td class="aux_intable_require">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td><input name="checkDate" type="text"
									class="required validate-date-yyyy-MM-dd less-equals-than-nowDate great-equals-than-violateDate"
									validateMessage="输入的检查日期必须小于等于当前系统时间,并且不能早于违规日期"
									value="<fmt:formatDate value="${violation.checkDate }" pattern="yyyy-MM-dd"/>"
									size="16" afterInsert="checkDateAfter" maxlength="10" /></td>
								<td width="4">&nbsp;</td>
								<td><img name="checkDateButton"
									src="${ctx}/images/ico_clock_month.gif" width="20" height="20" /><span
									id="checkDateAfter"></span></td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td class="aux_intable_td1">责任部门：</td>
						<td class="aux_intable_require"><pms:unitedSelect
							name="deptId" optionLabel="deptName" optionValue="deptId"
							selectText="请选择" className="select-one-required"
							value="${violation.deptId}" dataList="${burdenDeptList}"
							style="width:110px;" /></td>
						<td class="aux_intable_td1">违规日期：</td>
						<td class="aux_intable_require">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td><input name="violateDate" id="violateDate" type="text"
									class="required validate-date-yyyy-MM-dd  less-equals-than-nowDate"
									validateMessage="输入的违规日期必须小于等于当前系统时间"
									value="<fmt:formatDate value="${violation.violateDate }" pattern="yyyy-MM-dd"/>"
									size="16" afterInsert="violateDateAfter" maxlength="10" /></td>
								<td width="4">&nbsp;</td>
								<td><img name="violateDateButton"
									src="${ctx}/images/ico_clock_month.gif" width="20" height="20" /><span
									id="violateDateAfter"></span></td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td class="aux_intable_td1">违规类别：</td>
						<td class="aux_intable_require"><pms:unitedSelect
							name="categoryId" optionLabel="name" optionValue="keyword"
							className="select-one-required" value="${violation.categoryId}"
							selectText="请选择" dataList="${categoryList}" style="width:110px;" />
						</td>
						<td class="aux_intable_td1">整改完成日期：</td>
						<td class="aux_intable_require">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td><input name="completeDate" type="text"
									class="required validate-date great-equals-than-nowDate"
									validateMessage="输入的日期必须大于等于当前日期"
									value="<fmt:formatDate value="${violation.completeDate }" pattern="yyyy-MM-dd"/>"
									size="16" afterInsert="completeDateAfter99" maxlength="10" /></td>
								<td width="4">&nbsp;</td>
								<td><img name="completeDateButton"
									src="${ctx}/images/ico_clock_month.gif" width="20" height="20" /><span
									id="completeDateAfter99"></span></td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td height="64" class="aux_intable_td1">违规行为描述：</td>
						<td colspan="3" class="aux_intable_require_more"><textarea
							id="description" name="description" cols="60" rows="3"
							class="textareatext required max-length-100">${violation.description }</textarea></td>
					</tr>
				</table>
				</form>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</td>
</tr>
<tr>
	<td class="window_footer">
	<table border="0" cellspacing="0" cellpadding="0" align="right">
		<tr>
			<td>
			<table id="saveAdd" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td class="buttonOffLeft" id="btn1_21"></td>
					<td class="buttonOffMiddle" id="btn1_22"
						onClick="addViolation('save_add');"
						onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)"
						onblur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif"
						alt="" width="14" height="14" border="0" align="absbottom" />
					保存并新增</td>
					<td class="buttonOffRight" id="btn1_23"></td>
				</tr>
			</table>
			</td>
			<td class="btn_between_space"></td>
			<td>
			<table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td class="buttonOffLeft" id="btn1_41"></td>
					<td class="buttonOffMiddle" id="btn1_42"
						onClick="addViolation('add');" onMouseOver="btn_change_over(4)"
						onMouseOut="btn_change_out(4)" onblur="btn_change(4)"><img
						src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14"
						border="0" align="absbottom" /> 保 存</td>
					<td class="buttonOffRight" id="btn1_43"></td>
				</tr>
			</table>
			</td>
			<td class="btn_between_space"></td>
			<td>
			<table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td class="buttonOffLeft" id="btn1_31"></td>
					<td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();"
						onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)"
						onblur="btn_change(3)"><img
						src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14"
						border="0" align="absbottom" /> 关 闭</td>
					<td class="buttonOffRight" id="btn1_33"></td>
				</tr>
			</table>
			</td>
			<td class="btn_between_space"></td>
			<td class="btn_between_space"></td>
		</tr>
	</table>
	</td>
</tr>
</table>
</body>
<script type="text/javascript">
              Calendar.setup(
              {
	              inputField : "violateDate", // ID of the input field
	              ifFormat : "%Y-%m-%d", // the date format
	              button : "violateDateButton", // ID of the button
	              align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true
              }
              );
               Calendar.setup(
              {
	              inputField : "checkDate", // ID of the input field
	              ifFormat : "%Y-%m-%d", // the date format
	              button : "checkDateButton", // ID of the button
	              align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true
              }
              );
               Calendar.setup(
              {
	              inputField : "completeDate", // ID of the input field
	              ifFormat : "%Y-%m-%d", // the date format
	              button : "completeDateButton", // ID of the button
	              align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true
              }
              );
</script>
</html>